package com.dai.zhenfujin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.bumptech.glide.Glide;
import com.dai.zhenfujin.utils.ImageUtil;
import com.dai.zhenfujin.view.RatioImageView;
import com.dai.zhenfujin.view.ShowImagesDialog;

import java.util.List;

public class FansImagesAdpter extends BaseAdapter {
    private Context context;
    private List<String> beanList;
    private LayoutInflater inflater;


    public FansImagesAdpter(Context context, List<String> beanList) {
        this.context = context;
        this.beanList = beanList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return beanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(com.dai.zhenfujin.R.layout.itme_type_list2,null);
            holder.ivType = (RatioImageView)convertView.findViewById(com.dai.zhenfujin.R.id.iv_type);
          //  holder.iv_type2 = (RoundImageView)convertView.findViewById(com.dai.zhenfujin.R.id.iv_type2);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(beanList.get(position)).into(holder.ivType);

        if (beanList.size() < 2){
            //holder.iv_type2.setVisibility(View.VISIBLE);
          //  holder.ivType.setVisibility(View.GONE);
            ImageUtil.imageLoad(context,holder.ivType,beanList.get(position));
        }else {
          //  holder.iv_type2.setVisibility(View.GONE);
          //  holder.ivType.setVisibility(View.VISIBLE);
          Glide.with(context).load(beanList.get(position)).into(holder.ivType);
        }



        holder.ivType.setOnClickListener(v -> {
            ShowImagesDialog showImagesDialog = new ShowImagesDialog(context,beanList,position);
            showImagesDialog.show();
        });

        return convertView;
    }

    class ViewHolder {
        private RatioImageView ivType;
    }
}
